import { useEffect, useState } from 'react'
import { BannerItem, fetchBannerAPI } from '@/apis/home'
// import { log } from 'console'

function useBanner() {
  const [isLoading, setLoading] = useState<boolean>(false)
  const [banners, setBanners] = useState<BannerItem[]>([])

  useEffect(() => {
    const getBanners = async () => {
      try {
        setLoading(true)
        const res = await fetchBannerAPI()
        // console.log(res);
        setBanners(res.data.data)
        setLoading(false)
      } catch (error) {
        throw new Error('fetch banners error')
      }
    }
    getBanners()
  }, [])
  // 暴露数据channels
  return {
    banners,isLoading
  }
}

export { useBanner }
